package com.example.lenovo.contactlist;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements ContactAdapter.OnItemClickLitener {
    //联系人view
    private List<Contact> contactList = new ArrayList<>();
    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private ContactAdapter conAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initContact();
        initView();
        initEvent();
    }

    public void initView() {
        //联系人菜单view
        recyclerView = (RecyclerView) findViewById(R.id.contact_view);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        conAdapter = new ContactAdapter(contactList);

        recyclerView.setAdapter(conAdapter);


    }


    public void initEvent() {
        conAdapter.setOnItemClickLitener(this);
    }

    public void initContact() {
        Contact contact = new Contact("zwh", R.drawable.head);
        contactList.add(contact);
    }

    @Override
    public void onItemClick(int position) {
        System.out.println(contactList.get(position).getName());
        Intent intent = new Intent(MainActivity.this, ChatActivity.class);
        startActivity(intent);
    }
}
